package com.tanhua.dubbo.api;

import com.tanhua.model.mongo.Question;
import org.apache.dubbo.config.annotation.DubboService;
import org.bson.types.ObjectId;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;

import java.util.List;

/**
 * @Description:
 * @Create by: wanglei
 * @Date: 2021/11/7 12:52
 */
@DubboService
public class QuestionSoulApiImpl implements QuestionSoulApi{
    @Autowired
    private MongoTemplate mongoTemplate;

    //保存
    @Override
    public void save(Question question) {
        mongoTemplate.save(question);
    }


    //根据soulid,查询
    @Override
    public List<Question> findBySoulId(String soulIdStr) {
        Query query = Query.query(Criteria.where("soulId").is(soulIdStr));
        List<Question> questions = mongoTemplate.find(query, Question.class);
        return questions;
    }

    //根据questionId查询
    @Override
    public Question findById(ObjectId questionId) {
        Question question = mongoTemplate.findById(questionId, Question.class);
        return question;
    }
}
